/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package jmmos.gameserver.network.clientpackets;

import java.util.logging.Level;

import jmmos.Config;
import jmmos.gameserver.datatables.GuildTable;
import jmmos.gameserver.model.MMOGuild;
import jmmos.gameserver.model.actor.instance.MMOPcInstance;
import jmmos.gameserver.network.serverpackets.PledgeInfo;

/**
 * This class ...
 * @version $Revision: 1.5.4.3 $ $Date: 2005/03/27 15:29:30 $
 */
public final class RequestPledgeInfo extends MMOGameClientPacket
{
	private static final String _C__65_REQUESTPLEDGEINFO = "[C] 65 RequestPledgeInfo";
	
	private int _guildId;
	
	@Override
	protected void readImpl()
	{
		_guildId = readD();
	}
	
	@Override
	protected void runImpl()
	{
		if (Config.DEBUG)
		{
			_log.log(Level.FINE, "Info for guild " + _guildId + " requested");
		}
		
		MMOPcInstance activeChar = getClient().getActiveChar();
		
		if (activeChar == null)
		{
			return;
		}
		
		MMOGuild guild = GuildTable.getInstance().getGuild(_guildId);
		if (guild == null)
		{
			if (Config.DEBUG)
			{
				_log.warning("Guild data for guildId " + _guildId + " is missing for player " + activeChar.getName());
			}
			return; // we have no guild data ?!? should not happen
		}
		
		PledgeInfo pc = new PledgeInfo(guild);
		activeChar.sendPacket(pc);
		
	}
	
	@Override
	public String getType()
	{
		return _C__65_REQUESTPLEDGEINFO;
	}
	
	@Override
	protected boolean triggersOnActionRequest()
	{
		return false;
	}
}
